home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / uemlsrc.arc / main.c < prev    next >
C/C++ Source or Header  |  1987-08-24  |  23KB  |  645 lines

  1. /*
  2.  * This program is in public domain; written by Dave G. Conroy.
  3.  * This file contains the main driving routine for the Micro-
  4.  * EMACS screen editor.  This version began as the original
  5.  * small version by DGC.  It has been extensively expanded
  6.  * using versions 35 (a hybrid) and 36 (a direct descendent).
  7.  * This version includes a number of text functions that are
  8.  * not found in others and a word wrap algorithm different from
  9.  * 35 or 36.  It also contains a kermit module, real page movement,
  10.  * printer support and a shell command.  It is sort of a cross
  11.  * between ME and Perfect Writer version 1.03.
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include <ctype.h>
  16. #include <osbind.h>
  17. #include "ed.h"
  18. #if ST
  19. #include "keycode.h"
  20. #endif
  21.  
  22. #if     VMS
  23. #include        <ssdef.h>
  24. #define GOOD    (SS$_NORMAL)
  25. #endif
  26.  
  27. #ifndef GOOD
  28. #define GOOD    0
  29. #endif
  30.  
  31. char *version = "v. 33 25-January-1987";
  32.  
  33. int     currow;                         /* Working cursor row           */
  34. int     curcol;                         /* Working cursor column        */
  35. int     fillcol = 76;                   /* Current fill column          */
  36. int     indcol;                         /* Current indent column        */
  37. int     thisflag;                       /* Flags, this command          */
  38. int     lastflag;                       /* Flags, last command          */
  39. int     curgoal;                        /* Goal column                  */
  40. int     isnprint;                       /* Print buffer in use          */
  41. int     glmode = BMNWRAP;               /* Begin in fundamental mode    */
  42. BUFFER  *curbp;                         /* Current buffer               */
  43. WINDOW  *curwp;                         /* Current window               */
  44. BUFFER  *bheadp;                        /* BUFFER listhead              */
  45. WINDOW  *wheadp;                        /* WINDOW listhead              */
  46. BUFFER  *blistp = NULL;                 /* Buffer list BUFFER           */
  47. BUFFER  *bmacrp = NULL;                 /* Compiled macros BUFFER       */
  48. short   kbdm[NKBDM] = CTLX|')';         /* Macro                        */
  49. short   *kbdmip;                        /* Input  for above             */
  50. short   *kbdmop;                        /* Output for above             */
  51. char    pat[NPAT];                      /* Pattern                      */
  52. char    rpat[NPAT];                     /* Replacement pattern          */
  53. char    prnhdr[NPAT];                   /* Print header                 */
  54. char    prndate[NPAT];                  /* Print date                   */
  55. char    lastbuf[NBUFN];                 /* Last buffer name             */
  56. char    defpath[128];                   /* default path name            */
  57. int     defdrive;                       /* default drive                */
  58. long    buserr;                         /* Address of gemdos busserr    */
  59. long    adderr;                         /* Address of gemdos address err*/
  60. long    progend;                        /* end of program after init    */
  61.  
  62. main(argc, argv)
  63. int argc;
  64. char *argv[];
  65. {
  66.         register int    c;
  67.         register int    f;
  68.         register int    n;
  69.         register int    mflag;
  70.         register int    prncnt;
  71.         register int    basec;
  72.         extern   int    errexit();
  73.         extern   long   sbrk();
  74.  
  75. #if     ALCYON
  76.         fclose(stdin);                          /* reduce overhead for */
  77.         fclose(stdout);                         /* unused file pointers */
  78.         fclose(stderr);
  79. #endif
  80.         isnprint = FALSE;
  81.         prncnt = 0;
  82.  
  83.         if (access("cc.ini",4) == NULL)         /* cc drive assignments */
  84.                 commfil(FALSE,HUGE);            /* and function key bind*/
  85.         strcpy(lastbuf, "main");                /* Work out the name of */
  86.         if (argc > 1)                           /* the default buffer.  */
  87.                 makename(lastbuf, argv[1]);
  88.         edinit(lastbuf);                        /* Buffers, windows.    */
  89.         vtinit();                               /* Displays.            */
  90.         update();
  91. #if     ST
  92.         defdrive = Dgetdrv();
  93.         Dgetpath(defpath,0);
  94.         buserr = Setexc(2,-1L);
  95.         adderr = Setexc(3,-1L);
  96.         Setexc(2,&errexit);                     /* Clean up screen on err */
  97.         Setexc(3,&errexit);
  98. #endif
  99.         if (access("uemail.mcr",4) == NULL)     /* default macro file   */
  100.                 {
  101.                 update();
  102.                 loadmac(FALSE);
  103.                 }
  104.         progend = sbrk(0);
  105.         if (argc > 1) {
  106.                 update();                       /* You have to update   */
  107.                 readin(argv[1]);                /* in case "[New file]" */
  108.         }
  109.         lastflag = 0;                           /* Fake last flags.     */
  110. loop:
  111.         update();                               /* Fix up the screen    */
  112.  
  113.         /* This is the print buffer code.  It's very rudimentary, but it
  114.          * works as long as the buffer in the printer does not get filled.
  115.          * On the initial call to the function print(), the printer is
  116.          * sent one 1536 byte buffer of data and isnprint is set to
  117.          * TRUE.  From then on the printer is sent 384 bytes of data after
  118.          * an arbitrary number of keystrokes is entered if the printer
  119.          * is ready.
  120.          */
  121.  
  122.         if(isnprint)                            /* We are printing a file */
  123.                 if (prncnt++ > 16)              /* Keystroke count      */
  124.                         if(PRNRDY)              /* Check LST: status */
  125.                                 {
  126.                                 prnbuf();       /* Send a buffer full */
  127.                                 prncnt = 0;
  128.                                 }
  129.         f = getkey();
  130.         if (shiftstatus == 17 || shiftstatus == 18)     /* CapsLock + Shift */
  131.                 c = tolower(f);
  132.         else
  133.                 c = f;
  134.         if (mpresf != FALSE) {
  135.                 mlerase();
  136.                 update();
  137.         }
  138.         f = FALSE;
  139.         n = 1;
  140.  
  141.         /* do META-# processing if needed */
  142.  
  143.         basec = c & ~META;              /* strip meta char off if there */
  144.         if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) {
  145.                  f = TRUE;               /* there is a # arg */
  146.                  n = 0;             /* start with a zero default */
  147.                  mflag = 1;             /* current minus flag */
  148.                  c = basec;             /* strip the META */
  149.                  while ((c >= '0' && c <= '9') || (c == '-')) {
  150.                           if (c == '-') {
  151.                                    /* already hit a minus or digit? */
  152.                                    if ((mflag == -1) || (n != 0))
  153.                                             break;
  154.                                    mflag = -1;
  155.                           } else {
  156.                                    n = n * 10 + (c - '0');
  157.                           }
  158.                           if ((n == 0) && (mflag == -1))  /* lonely - */
  159.                                    mlwrite("Arg:");
  160.                           else
  161.                                    mlwrite("Arg: %d",n * mflag);
  162.  
  163.                           c = getkey();   /* get the next key */
  164.                  }
  165.                  n = n * mflag;  /* figure in the sign */
  166.         }
  167.  
  168.         /* ^U expansion */
  169.  
  170.         if (c == (CTRL|'U')) {                  /* ^U, start argument   */
  171.                 f = TRUE;
  172.                 n = 4;                          /* with argument of 4 */
  173.                 mflag = 0;                      /* that can be discarded. */
  174.                 mlwrite("Arg: 4");
  175.                 while ((c=getkey()) >='0' && c<='9' || c==(CTRL|'U') || c=='-'){
  176.                         if (c == (CTRL|'U'))
  177.                                 n = n*4;
  178.                         /*
  179.                          * If dash, and start of argument string, set arg.
  180.                          * to -1.  Otherwise, insert it.
  181.                          */
  182.                         else if (c == '-') {
  183.                                 if (mflag)
  184.                                         break;
  185.                                 n = 0;
  186.                                 mflag = -1;
  187.